# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ... import pilelib as stack
from ...forms import klondike as klayout
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...piles import hanafuda as hstack
from ...utillib.misc import kwdefault

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class LittleEasy(cs.Hanafuda_Deck, game.Game):
    """
    Finish 1 deck by full seq on foundations.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout
        - row [7 horz S foundation, vert offset]
        - waste [1 E talon, no offset]
        - talon [1 NW, no offset]
        - foundation [4 horz N, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=cs.INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. No limit redeals.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

          Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build up in suit alone by same rank. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=FIRST)

        Init 2 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=0x1ddf3, name='Little Easy', category=cs.TYPE_HANAFUDA,
                    game_type=GT.GYPSY, decks=1, redeals=cs.INFINITE,
                    skill_level=SL.BALANCED, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _layout_ = klayout.KlondikeLayout
    _talon_ = Wrap(stack.WasteTalon, max_rounds=cs.INFINITE, num_deal=3)
    _waste_ = stack.WasteStack
    _foundation_ = hstack.Suit_Foundation
    _row_ = Wrap(hstack.RankSS_RowStack, base_rank=cs.FIRST)

    def _create_game(self, **kw):
        kwdefault(kw, rows=7, texts=True, playcards=10,
                          bases=l.RANKS)
        return super(LittleEasy, self)._create_game(**kw)

    def _start(self, **kw):
        """
        Deal initial cards for new game.
          - s[rows] 2 ea top.

        .. \_start([]) -> None
        """
        self.s['talon'].dealRow(flip=False, frames=0)
        self.s['talon'].dealRow()


class EasyTimesOne(LittleEasy):
    """
    Finish 1 deck by full seq on foundations.

    :CVariables:
      _layout_ : layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout
        - row [7 horz S foundation, vert offset]
        - waste [1 E talon, no offset]
        - talon [1 NW, no offset]
        - foundation [4 horz N, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=2, num_deal=3)

        Deal 1 card per `s.waste` on click. 1 redeals.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

          Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build up in suit alone by same rank. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=FIRST)

        Init 2 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=0x1ddf8, name='Easy ×1', category=cs.TYPE_HANAFUDA,
                    game_type=GT.GYPSY, decks=1, redeals=1,
                    skill_level=SL.BALANCED, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _talon_ = Wrap(stack.WasteTalon, max_rounds=2)


class Relax(EasyTimesOne):
    """
    Finish 1 deck by full seq on foundations.

    :CVariables:
      _layout_ : layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout
        - row [7 horz S foundation, vert offset]
        - waste [1 E talon, no offset]
        - talon [1 NW, no offset]
        - foundation [4 horz N, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=2, num_deal=3)

        Deal 1 card per `s.waste` on click. 1 redeals.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

          Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build up in suit by same rank. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack

        Init 2 card. Build down in rank by same suit with trash cards
        swap except Willow. Play any.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=0x1ddf9, name='Relax', category=cs.TYPE_HANAFUDA,
                    game_type=GT.GYPSY, decks=1, redeals=1,
                    skill_level=SL.BALANCED, version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    _row_ = Wrap(hstack.Rank_RowStack, strict=False)


class BigEasy(LittleEasy):
    """
    Finish 2 deck by full seq on foundations.

    :CVariables:
      _layout_ : layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout
        - row [11 horz S foundation, vert offset]
        - waste [1 E talon, no offset]
        - talon [1 NW, no offset]
        - foundation [4 horz N, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=cs.INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. No limit redeals.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

          Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build up in suit by same rank. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=FIRST)

        Init 2 card. Build down in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=0x1ddf4, name='Big Easy', category=cs.TYPE_HANAFUDA,
                    game_type=GT.GYPSY, decks=2, redeals=cs.INFINITE,
                    skill_level=SL.BALANCED, altnames=(
                    'Little Easy (2 decks)'), version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    def _create_game(self, **kw):
        kw.setdefault('rows', 11)
        super(BigEasy, self)._create_game(**kw)


class EasySupreme(BigEasy):
    """
    Finish 4 deck by full seq on foundations.

    :CVariables:
      _layout_ : layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout
        - row [11 horz S foundation, vert offset]
        - waste [1 E talon, no offset]
        - talon [1 NW, no offset]
        - foundation [4 horz N, no offset]

      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=cs.INFINITE, num_deal=3)

        Deal 3 card per `s.waste` on click. No limit redeals.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

          Init 3 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build down in suit alone by same rank. Play top.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.RankSS_RowStack (base_rank=FIRST)

        Init 2 card. Build up in rank by same suit. Play any. Base 1st
        rank.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.DefaultHint
    """
    __info__ = dict(id=0x1ddf5, name='Easy Supreme',
                    category=cs.TYPE_HANAFUDA, game_type=GT.GYPSY, decks=4,
                    redeals=cs.INFINITE, skill_level=SL.BALANCED, altnames=(
                    'Little Easy (4 decks)'), version='0.50fc')
    __author__ = 'Mt. Hood Playing Card'
    __version__ = 7.70

    def _create_game(self, **kw):
        kw.setdefault('playcards', 14)
        super(EasySupreme, self)._create_game(**kw)

PROVIDES = [BigEasy, EasySupreme, EasyTimesOne, LittleEasy, Relax]